<?php

namespace App\Http\Controllers\Api\V1;

use App\Http\Controllers\Controller;
use App\Http\Resources\BookHistoryResource;
use App\Models\BookHistory;
use Illuminate\Http\Request;

/***
 * 书籍阅读历史
 * Class BookHistoryController
 * @package App\Http\Controllers\Api\V1
 */
class BookHistoryController extends ApiController
{
    //获取我的阅读历史
    public function getHistoryInfo(BookHistory $history, Request $request)
    {
        $query = $history->newQuery();
        if ($request->has('module_id')) {
            $query->where('module_id', $request->module_id);
        }
        if ($this->getUserId()) {
            $query->where('user_id', $this->getUserId());
        }
        if ($request->has('book_id')) {
            $query->where('book_id', $request->book_id);
        }
        $list = $query->paginate();
        return $this->success('成功', BookHistoryResource::collection($list));
    }
}
